conf = require("../config")
if not conf.treesitter.enabled then return {} end

parsers = {
  "c", "cpp",
  "lua",
  "rust",
  "python",
  "verilog",
  "scala",
  "bash",
  "markdown", "markdown_inline",
  "make",
}

highlight_filetype = {
  "c", "cpp",
  "lua",
  "rust",
  "python",
  "verilog", "systemverilog",
  "scala",
  "bash",
  "markdown",
  "make",
}

highlight_disable = {
  -- "c", "cpp"
  "lua",
  "rust",
  -- "python",
  -- "verilog",
  -- "bash",
}


return {
  "nvim-treesitter/nvim-treesitter",
  build = ':TSUpdate',
  event = { 'BufReadPost', 'BufNewFile' },
  config = function ()
    require("nvim-treesitter.configs").setup({
      ensure_installed = parsers,
      sync_install = false,
      auto_install = false,
      highlight = {
        enable = true,
        disable = highlight_disable,
        additional_vim_regex_highlighting = false,
      },
      indent = {
        enable = true,
      }
    })

    -- *
    -- * Treesitter already supported asynchronous
    -- *
    -- vim.api.nvim_create_autocmd({ "BufEnter" }, {
    --   pattern = "*",
    --   callback = function ()
    --     for _, filetype in ipairs(highlight_filetype) do
    --       if filetype ~= "verilog" or filetype ~= "systemverilog" then
    --         vim.defer_fn(function ()
    --           vim.cmd("TSBufEnable highlight")
    --         end, 1)
    --       else
    --         vim.cmd("TSBufEnable highlight")
    --       end
    --     end
    --   end
    -- })
  end
}
